package servlet;

import dao.FoodD;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/update_food")
public class update_food extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        response.setContentType("text/html;charset=utf-8");
        response.setCharacterEncoding("utf-8");
        request.setCharacterEncoding("utf-8");

        PrintWriter out = response.getWriter();
        FoodD foodD = new FoodD();

        String fid = request.getParameter("fid");
        String fname = request.getParameter("fname");
        String fdesc = request.getParameter("fdesc");
        String fimg = request.getParameter("fimg");
        String ftype = request.getParameter("ftype");
        String fdate = request.getParameter("fdate");

        try {
            foodD.updateFoodInfo(fid, fname,fdesc,fimg,ftype,fdate);
        }
        catch (Exception e){
            out.print(e);
        }
        response.sendRedirect("one_page_food");
    }
}
